/**
 * @file boards\gd32f303cx_mr7202\config\options.h
 *
 * Copyright (C) 2022
 *
 * options.h is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author HinsShum hinsshum@qq.com
 *
 * @encoding utf-8
 */
#ifndef __BOARD_OPTIONS_H
#define __BOARD_OPTIONS_H

#ifdef __cplusplus
extern "C"
{
#endif

/*---------- includes ----------*/
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "cpu.h"
#include "misc.h"
#include "flash_map.h"
#include "heap.h"
#include "gd32f10x.h"

/*---------- macro ----------*/
#ifdef NDEBUG
#define CONFIG_SILECE
#define CONFIG_UNUSE_FULLDUPLEX_SERIAL_MAC
#endif

/* system delay function
 */
#define __delay_ms(ms)                  mdelay(__ms2ticks(ms))
#define __delay_us(us)                  udelay(us)
#define __get_ticks()                   tick_get()
#define __get_ticks_from_isr()          tick_get_from_isr()
#define __enter_critical()              enter_critical()
#define __exit_critical()               exit_critical()
#define __enter_critical_from_isr()     enter_critical()
#define __exit_critical_from_isr()      exit_critical()
#define __system_reset()                cpu_reset()
#define __malloc(size)                  heap_malloc(size)
#define __free(ptr)                     heap_free(ptr)
#define __ticks2ms(ticks)               (ticks)
#define __ms2ticks(ms)                  (ms)

/* print macros
 */
#ifndef CONFIG_SILECE
#include <stdio.h>
#define xlog_error(x, y...)             printf(COLOR_RED x, ##y)
#define xlog_warn(x, y...)              printf(COLOR_YELLOW x, ##y)
#define xlog_message(x, y...)           printf(COLOR_GREEN x, ##y)
#define xlog_info(x, y...)              printf(COLOR_WHITE x, ##y)
#define xlog_cont(x, y...)              printf(x, ##y)
#define xlog_tag_error(tag, x, y...)    printf(COLOR_RED "(" tag ")" x, ##y)
#define xlog_tag_warn(tag, x, y...)     printf(COLOR_YELLOW "(" tag ")" x, ##y)
#define xlog_tag_message(tag, x, y...)  printf(COLOR_GREEN "(" tag ")" x, ##y)
#define xlog_tag_info(tag, x, y...)     printf(COLOR_WHITE "(" tag ")" x, ##y)
#else
#define xlog_error(x, y...)
#define xlog_warn(x, y...)
#define xlog_message(x, y...)
#define xlog_info(x, y...)
#define xlog_cont(x, y...)
#define xlog_tag_error(tag, x, y...)
#define xlog_tag_warn(tag, x, y...)
#define xlog_tag_message(tag, x, y...)
#define xlog_tag_info(tag, x, y...)
#endif

/* protocol debug definition
 */
#ifndef CONFIG_SILECE
#define CONFIG_SERIAL_MAC_DEBUG
#endif

/* system interrupt priority macro
 */
#define __PRIORITY_MSK                  ((1UL << __NVIC_PRIO_BITS) - 1UL)
#define _PRIORITY_MAKE(prio)            (__PRIORITY_MSK - (prio & __PRIORITY_MSK))
#define NVIC_PRIORITY_MAKE(prio)        NVIC_EncodePriority(NVIC_GetPriorityGrouping(), _PRIORITY_MAKE(prio), 0)

/* peripherals interrupt priority defition
 */
#define CONFIG_PRIORITY_SYSTICK                     0
#define CONFIG_PRIORITY_MOBUS_T35                   1
#define CONFIG_PRIORITY_MOBUS_COM                   2
#define CONFIG_PRIORITY_EXTI0                       3

/*---------- type define ----------*/
/*---------- variable prototype ----------*/
/*---------- function prototype ----------*/

#ifdef __cplusplus
}
#endif
#endif /* __BOARD_OPTIONS_H */
